feat: add initial HarmonyOS (OHOS) support#30917
Conversation
…ve lazyCpus - Replace hardcoded /proc/cpuinfo key patterns with flexible ': ' separator parsing (handles OHOS multi-tab/space format: 'CPU implementer\t\t: 0x48') - Add ARM JEP106 implementer + part decoder (ARM, HiSilicon, Qualcomm, Apple, etc.) - Add Hardware field support, set on ALL CPUs (OHOS: 'HUAWEI KirinX90') - Remove lazyCpus getter/setter wrapper (crashed on OHOS JSC with closure error) - Upstream JSType.zig used as-is (PromiseReaction split supersedes our JSScriptFetcher fix) - Adopt new file paths: src/runtime/node/node_os.zig, src/runtime/webcore/Blob.zig
- bun-spawn.cpp: use fork() instead of vfork() on OHOS (seccomp blocks clone); skip sigaction reset (blocked syscalls); use _exit() not exit_group - c-bindings.cpp: skip close_range on OHOS - Blob.zig: push nested array onto stack to prevent element loss
- config.ts: add ohos OS type, Config fields, resolveConfig path, findOhosSdkRoot - flags.ts: add OHOS CPU target, cross-compilation, and linker flags - tools.ts: add LLVM 22 path for OHOS, update install hint
- scripts/build.ts: register ohosSysroot/ohosSdkRoot CLI args - deps/cares.ts: exclude HAVE_MEMMEM and HAVE_GETSERVBYPORT_R for OHOS musl - deps/zstd.ts: restore original build flags
- config.ts: add hostCc field for host-native compiler (GCC not LLVM clang) - source.ts: fix dep_host_cc rule to use cfg.hostCc not cfg.cc - source.ts: add RUSTUP_TOOLCHAIN=stable + linker for OHOS cargo builds - fetch-cli.ts: N/A (patch format fixed instead) - deps/lolhtml.ts: add OHOS rustTarget + cdylib removal patch - deps/cares.ts: exclude GNU extensions for OHOS musl - patches/lolhtml/crate-type.patch: remove cdylib crate-type (no .so linking)
…/errpipe - flags.ts: add -std=gnu++23 for OHOS (std::span requires C++20+) - webkit.ts: add OHOS cmake cross-compile config (sysroot, libc++, ICU) - bun-spawn.cpp: use fork() not vfork() on OHOS, fix errpipe/pthread - c-bindings.cpp: skip close_range on OHOS
…egen - scripts/build/bun.ts: add OHOS system libs block (-lc -lpthread -ldl) and ICU library path (-L ohosIcuDir/lib) for local WebKit builds - scripts/build/deps/webkit.ts: add -std=gnu++23 to OHOS local WebKit cmake flags (required by new WebKit C++23 features) - scripts/build/flags.ts: remove -DU_DISABLE_RENAMING=1 (ICU versioned symbol mismatch with prebuilt ICU libs); split OHOS -std=gnu++23 into its own flag block - scripts/build/zig.ts: codegenThreads=8 for OHOS (more shards = smaller per-shard = less peak memory on 11GB RAM build VM) - src/jsc/bindings/ZigGlobalObject.h: add TypeCastTraits specialization for Zig::GlobalObject (required by new WebKit TypeCast system)
- test_all_in_one.js: 376-item consolidated test across 63 groups covering Bun API, Node.js compat, Web API, SQLite, WebSocket, TCP, HTTP server, compression, crypto, JS standard library - test_perf.js: 77-item performance benchmark (JSON, Array, String, Buffer, crypto, async, Math)
Triggers on push to ohos-aarch64 and WebKit changes. Builds WebKit locally, then Bun, packages artifact. Requires self-hosted runner with OHOS SDK pre-installed.
- Apply all 5 rounds of CodeRabbit improvements from PR oven-sh#30315: lazyCpus simplification, per-CPU model finalization, Hardware fallback, colon-only parsing, const-correctness, helper extraction, exact isKnownArmPart checks
Switch to PIE linking to allow fork/clone through OHOS seccomp. Skip fstat on socketpair fds (OHOS blocks EACCES on these). spawnSync no longer hangs; child exec may get SIGSYS due to seccomp restrictions on non-whitelisted processes.
…ript scripts/ohos/build.sh - full build pipeline: env check → cross-libs → source fetch → WebKit → Bun → package → publish scripts/ohos/prepare-cross-libs.sh - cross-compile libc++/libc++abi/libunwind for aarch64-linux-ohos using OHOS SDK LLVM 22
Fix Zig compilation errors when JSValue.get() returns an error union of optional. Use 'try' to unwrap the error and check for null before calling methods on the optional.
The hunk header was changed from 35 to 30 lines and an em dash was re-introduced, breaking the patch application. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Multiple unresolved conflict zones from the pr/ohos-platform-support merge left .rs files with broken delimiter matching, causing CI compilation failure. All conflicts were between our OHOS-specific code and upstream's non-OHOS version; kept our side for all. Also fixes the zstd patch corruption re-introduced by the same merge.
|
Quick update: CI is now passing on our fork 🎉
Branch: All 4 rounds of CodeRabbit suggestions resolved. Would appreciate a CI trigger and review when you get a chance. 🙏 |
…rm64 # Conflicts: # src/sys/linux_syscall.rs
Upstream hardening commit (0b20408) added deny(dead_code) which flags this OHOS-specific open() wrapper. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
The open() wrapper was added during the OHOS port but never called — all callers use openat(AT_FDCWD, ...) instead. Removed to fix dead_code lint error from upstream hardening (0b20408).
|
I'm actively developing apps targeting HarmonyOS and Bun would be a key part of our toolchain. This PR appears high quality — 89.5% test pass rate on real device, aligned with main, CodeRabbit issues resolved. Could a maintainer clarify what's needed to move this forward? |
…ess.release - fs-birthtime-linux.test.ts: OHOS filesystem doesn't support birthtime (statx returns 0) - process.test.js: OHOS release URL uses different platform string Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- spawnTimeout: 5s → 15s - spawnBunTimeout: 20s → 60s - testTimeout: 3min → 5min - integrationTimeout: 5min → 10min - getNodeParallelTestTimeout default: 20s → 300s Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
tmpdir() hardcoded /tmp on Linux without checking TMPDIR env var. OHOS has read-only /tmp, causing EROFS on mkdtemp. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
OHOS SELinux blocks linkat() during bun install package linking. When linkat returns EPERM or EACCES, fall back to open+copy_file + fchmod to preserve permissions. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Native binary packages (.node files) could still fail with EPERM on File::create during copy_file fallback. Now unlinks the stale file first before retrying. Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- Retry mechanism (3 retries, matching runner.node.mjs --retries=3) - Per-test watchdog timeout (300s, bundler 900s) - Bun internal --timeout passed to each test - Background process throttling (compatible with OHOS busybox) - Same test file discovery patterns as upstream Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Includes: yaml fix, hardening round 2, memory reduction Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
|
Latest update — PR branch synced with 13 additional commits: Changes since last update
Test results (on-device)
Build statusPR branch Would still appreciate a maintainer CI trigger and review when you have time. 🙏 |
Adds initial support for building Bun on HarmonyOS (OHOS) aarch64.
C++ Runtime Adaptations
Rust Runtime
Build System
Patches & Scripts
Tested: 53,391 test cases on OHOS device, 47,759 PASS (89.5%)